package com.xbell.app.sys.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.nacos.common.utils.DateFormatUtils;
import com.xbell.app.sys.common.PageInfo;
import com.xbell.app.sys.common.ResponseMessage;
import com.xbell.app.sys.service.HdglServiceI;

import io.swagger.annotations.Api;

@RestController
@RequestMapping(value="home")
@Api(tags="home控制器")
public class HomeController {
	
	@Autowired
	HdglServiceI hdglServiceI;
	
	@GetMapping("/")
	//@RateLimiter(name = "backendA",fallbackMethod="fallback")
	public ResponseMessage<Object> home(String say){
//		for(int i=0;i<100;i++) {
//			new Thread() {
//				public void run() {
//					HomeController.this.test();
//				}
//			}.start();
//			
//		}
		return ResponseMessage.ok(say);
	}
	
	//@RateLimiter(name = "backendA",fallbackMethod="fallback")
	public void test() {
		System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
	}
	
	public ResponseMessage<Object> fallback(String say,Throwable th) {
	    System.out.println(say+"Handled the exception when the CircuitBreaker is open");
	    return ResponseMessage.ok(say+"进入限流"); 
	}
	
	
	@GetMapping("allLogs")
	public ResponseMessage<Object> allLogs(PageInfo pg,String title){
		return ResponseMessage.ok(this.hdglServiceI.allLogs(pg, title));
	}
	
	@PostMapping("delLog")
	public ResponseMessage<Object> delLog(@RequestBody String id){
		return ResponseMessage.ok(this.hdglServiceI.delLog(id));
	}
}
